package wangxu

import (
	"github.com/gogf/gf/v2/text/gstr"
	"github.com/gogf/gf/v2/util/gconv"
)

// # model

type Token struct {
	Version   string
	UserId    int
	ProductId int
	Hash      string
}

// # tool & api

type wangxuPassport struct{}

func (r *wangxuPassport) ParseToken(token string) *Token {
	parts := gstr.SplitAndTrim(token, ",")
	if len(parts) >= 4 {
		return &Token{
			Version:   parts[0],
			UserId:    gconv.Int(parts[1]),
			ProductId: gconv.Int(parts[2]),
			Hash:      parts[3],
		}
	}

	return nil
}
